package com.wangxin.model;

import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;

import com.jfinal.plugin.activerecord.Db;

public class ShortMsg {

	private String sismsid; 
	private String extcode;
	private String destaddr;
	private String messagecontent;
	private int reqdeliveryreport=1;
	private int msgfmt=15; 
	private int sendmethod=0;
	private Date requesttime;
	private String applicationid;
	public String getSismsid() {
		return sismsid;
	}
	public void setSismsid(String sismsid) {
		this.sismsid = sismsid;
	}
	public String getExtcode() {
		return extcode;
	}
	public void setExtcode(String extcode) {
		this.extcode = extcode;
	}
	public String getDestaddr() {
		return destaddr;
	}
	public void setDestaddr(String destaddr) {
		this.destaddr = destaddr;
	}
	public String getMessagecontent() {
		return messagecontent;
	}
	public void setMessagecontent(String messagecontent) {
		this.messagecontent = messagecontent;
	}
	public int getReqdeliveryreport() {
		return reqdeliveryreport;
	}
	public void setReqdeliveryreport(int reqdeliveryreport) {
		this.reqdeliveryreport = reqdeliveryreport;
	}
	public int getMsgfmt() {
		return msgfmt;
	}
	public void setMsgfmt(int msgfmt) {
		this.msgfmt = msgfmt;
	}
	public int getSendmethod() {
		return sendmethod;
	}
	public void setSendmethod(int sendmethod) {
		this.sendmethod = sendmethod;
	}
	public Date getRequesttime() {
		return requesttime;
	}
	public String getRequesttimeStr(){
		return DateFormatUtils.format(getRequesttime(), "yyyy-MM-dd HH:mm:ss");
	}
	public void setRequesttime(Date requesttime) {
		this.requesttime = requesttime;
	}
	public String getApplicationid() {
		return applicationid;
	}
	public void setApplicationid(String applicationid) {
		this.applicationid = applicationid;
	}
	
	public int sendMsg(){
		String sqlTemplate = "insert into sms_outbox (sismsid, extcode, destaddr, messagecontent, reqdeliveryreport,msgfmt,sendmethod,requesttime,applicationid)values('%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s')";
		String sql = String.format(sqlTemplate, getSismsid(), getExtcode(), getDestaddr(), getMessagecontent(), getReqdeliveryreport(), getMsgfmt(), getSendmethod(), getRequesttimeStr(), getApplicationid());
		return Db.use("sms").update(sql);
	}
}
